﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>商城信息</title>
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="~/Content/jquery-easyui-1.4.2/demo.css">
    <link href="~/Content/Styles/Order.css" rel="stylesheet" />
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="~/Content/jquery-easyui-1.4.2/jquery.easyui.min.js"></script>
    <script src="~/Content/jquery-easyui-1.4.2/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/Script/jquery.Jcrop.css" rel="stylesheet" />
    <script src="~/Content/jquery-easyui-1.4.2/jquery.Jcrop.js"></script>
    <script src="~/Content/layui/layui.js"></script>
    <link href="~/Content/layui/css/layui.css" rel="stylesheet" />

    @*KindEditor富文本编辑器*@
    <script src="~/Content/kindeditor/kindeditor-all.js"></script>
    <script src="~/Content/kindeditor/kindeditor-all-min.js"></script>
    <link href="~/Content/kindeditor/themes/default/default.css" rel="stylesheet" />
    <script src="~/Content/kindeditor/lang/zh-CN.js"></script>

    <script>
        var Information_editor;
        $(function () {
            initTable();

            KindEditor.ready(function (K) {
                Information_editor = K.create('#Information_content', {
                    uploadJson: '../Content/kindeditor/asp.net/upload_json.ashx',
                    fileManagerJson: '../Content/kindeditor/asp.net/file_manager_json.ashx',
                    allowFileManager: true,
                    allowImageUpload: false, //上传图片框本地上传的功能，false为隐藏，默认为true
                    allowImageRemote: true, //上传图片框网络图片的功能，false为隐藏，默认为true
                    allowFileManager: true, //浏览图片空间
                    filterMode: false, //HTML特殊代码过滤
                });
            });
        });

        //初始化表格 获取所有消息
        function initTable() {
            $('#View').datagrid({
                iconCls: 'icon-user',
                loadMsg: '数据加载中...',
                nowrap: true,
                autoRowHeight: true,
                singleSelect: true,
                striped: true,
                url: '/Order_Information/getgrids',
                sortName: 'UpdateTime',
                sortOrder: 'desc',
                border: true,
                remoteSort: false,
                idField: 'InformationID',
                pageSize: 20,
                pageList: [20],
                pagination: true,
                rownumbers: true,
                columns: [[
                    { field: 'InformationID', title: 'ID', sortable: true, hidden: true },                    
                    { field: 'UserID', title: '用户ID', hidden: true },
                    { field: 'Title', title: '标题', sortable: true, width: 150 },  
                    {
                        field: 'Type', title: '消息类型', sortable: true, formatter: function (value) {
                            if (value == 1) {
                                return "消息";
                            }
                            else if (value == 2) {
                                return "促销活动";
                            }
                            else if (value == 3) {
                                return "通知";
                            }
                            else {
                                return null
                            }
                        }
                    },
                    {
                        field: 'Contents', title: '内容', width: 350, formatter: function (value) {
                            if (value != null) {
                                return value.replace(/</g, '≮').replace(/>/g, '≯').replace(/&#xa;/g, '↓');
                            } else {
                                return null
                            }
                        }
                    },
                    { field: 'UpdateTime', title: '更新时间', hidden: true },
                ]],
                toolbar: '#tb1',
                onLoadSuccess: function (data) {
                    if (data) {
                        $.each(data.rows, function (index, item) {
                            if (item.IsCheck) {
                                $('#View').datagrid('checkRow', index);
                            } else {
                                $('#View').datagrid('uncheckRow', index);
                            }
                        });
                    }
                }
            });
        }        

        //添加信息对话框
        function AddDialog() {
            filePath = "";
            $('#editDialog').dialog('open').dialog('setTitle', '新增商城消息');
            ClearTexts();
            document.getElementById("ok").style.display = "block";
        }

        //修改信息对话框
        function UpdateDialog() {
            filePath = "";
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "修改信息");
                BingUpdates();
                document.getElementById("ok").style.display = "block";
            }
            else {
                $.messager.alert("友情提示", "每次只能修改一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //删除信息对话框
        function DeleteDialog() {
            var checkdata = $("#View").datagrid("getSelections");//获取整行数据
            if (checkdata.length == 1) {
                var checkdata = $("#View").datagrid("getSelections")[0];//获取整行数据
                var postdata = {
                    InformationID: checkdata.InformationID,
                    UserID: checkdata.UserID,
                    Title: checkdata.Title,
                    Type: checkdata.Type,
                    Contents: checkdata.Contents.replace(/</g, '≮').replace(/>/g, '≯').replace(/&#xa;/g, '↓'),
                };
                //console.log(postdata);
                //发送异步请求删除数据
                $.messager.confirm("删除信息", "您确认删除<font color='Red' size='3'>" + checkdata.Title + "</font>这条信息吗？", function (Del) {
                    if (Del) {
                        $.post("/Order_Information/UpdateOrder_Information?Tag=" + 3, postdata, function (data) {
                            if (data == "1") {
                                $.messager.alert("友情提示", "删除成功");
                                //清空原有数据
                                var item = $('#View').datagrid('getRows');
                                if (item) {
                                    for (var i = item.length - 1; i >= 0; i--) {
                                        var index = $('#View').datagrid('getRowIndex', item[i]);
                                        $('#View').datagrid('deleteRow', index);
                                    }
                                }
                                $('#View').datagrid('loadData', { total: 0, rows: [] });
                                initTable();
                                //$("#View").datagrid('reload');
                            }
                            else {
                                $.messager.alert("友情提示", "删除失败:" + data);
                            }
                        });
                    }
                });
            }
        }
        
        //信息明细对话话框
        function DetailDialog() {
            var UpdateInfoID = $("#View").datagrid("getSelections");
            if (UpdateInfoID.length == 1) {
                $("#editDialog").dialog("open").dialog("setTitle", "信息明细");
                BingUpdates();
                document.getElementById("ok").style.display = "none";
            }
            else {
                $.messager.alert("友情提示", "每次只能查看一行数据，你已经选择了<font color='red' size='6'>" + UpdateInfoID.length + "</font>行");
            }
        }

        //获取修改信息
        function BingUpdates() {
            //首先获取选中的商品信息
            var checkdata = $("#View").datagrid("getSelections")[0];
            
            if (checkdata != null) {
                $("#InformationID").html(checkdata.InformationID)  //信息id
                $("#UserID").html(checkdata.UserID)  //用户id
                $("#Title").val(checkdata.Title);   //标题
                $("#Type").combobox('setValue', checkdata.Type) //类型
                KindEditor.html('#Information_content', checkdata.Contents); //内容                
            }
            //console.log(checkdata);
        }
        
        //清空文本框中的值
        function ClearTexts() {
            $("#InformationID").html("");
            $("#UserID").html("");
            $("#Title").val("");
            $("#Type").combobox('setValue', "消息");
            KindEditor.html("#Information_content", "");           
        }

        //保存
        function submitForm() {
            //首先判断前台的验证是否通过
            var valid = $('#editController').form('validate');
            if (valid == false) {
                return false;
            }
            Information_editor.sync();
            Information_content = document.getElementById('Information_content').value;//获取内容
            if (Information_content) {
                Information_content = Information_content.replace(/</g, '≮').replace(/>/g, '≯').replace(/&#xa;/g, '↓');
            }           
            //console.log(Information_content);
            var postdata = {
                InformationID: $("#InformationID").html(),
                UserID: $("#UserID").html(),
                Title: $("#Title").val(),
                Type: $("#Type").combobox('getValue'),
                Contents: Information_content,
            };
            //console.log(postdata);
            var Tag = 1;
            if (postdata.InformationID != "") {
                Tag = 2;
            }
            if ($("#Title").val() == null || $("#Title").val() == "") {
                alert("标题需必填！");
            }
            else if ($("#Type").combobox('getValue') == null || $("#Type").combobox('getValue') == "") {
                alert("类型需必选！");
            }
            else if (Information_content == null || Information_content == "") {
                alert("商品概述需必填！");
            }            
            else {
                //使用异步实现修改用户信息
                $.post("/Order_Information/UpdateOrder_Information?Tag=" + Tag, postdata, function (date) {
                    if (date == "1") {
                        if (Tag == 1) {
                            $("#editDialog").dialog('close');
                            $.messager.alert("提示", "添加成功");
                            $("#View").datagrid('reload');
                        }
                        else {
                            $("#editDialog").dialog('close');
                            $.messager.alert("提示", "修改成功");
                            $("#View").datagrid('reload');
                        }
                    }
                    else {
                        $.messager.alert("友情提示", "修改失败，请检查");
                    }
                });
            }
        }
        
    </script>

    <style>
        .dig-table {
            border: 0px solid black;
            line-height: 32px;
            width: 90%;
        }

        .box {
            position: fixed;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.2);
            display: none;
        }

        td label {
            padding-left: 5px;
            color: red;
        }
    </style>
</head>
<body style="padding: 0">
    <div>
        <table id="View" border="0"></table>
    </div>

    <div id="tb1" style="background-color: #F4F4F4">
        <div style="margin-bottom: 5px">
            <a href="#" id="btndetail" class="easyui-linkbutton" iconcls="icon-more" onclick="DetailDialog()" plain="true">明细</a>
            <a href="#" id="btnadd" class="easyui-linkbutton" iconcls="icon-add" onclick="AddDialog()" plain="true">新增</a>
            <a href="#" id="btnedit" class="easyui-linkbutton" iconcls="icon-edit" onclick="UpdateDialog()" plain="true">修改</a>
            <a href="#" id="btndell" class="easyui-linkbutton" iconcls="icon-cancel" onclick="DeleteDialog()" plain="true">删除</a>
        </div>        
    </div>

    <div id="editDialog" class="easyui-dialog" style="width:900px; padding: 10px; padding:fixed; top:5px;" closed="true" resizable="true" modal="true" buttons="#dlg-buttons" align="center">
        <form id="editController" method="post" novalidate="novalidate">
            @using (Html.BeginForm("ToLead", "PhotoManagerPro", FormMethod.Post, new { enctype = "multipart/form-data", id = "form1" }))
            {
                <table id="tbledit" class="dig-table">
                    <tr style="display:none;">
                        <td class="fr">商品ID：</td>
                        <td>
                            <span id="InformationID" name="InformationID" ></span>
                        </td>
                        <td class="fr">用户ID：</td>
                        <td>
                            <span id="UserID" name="UserID" ></span>
                        </td>
                    </tr>

                    <tr>
                        <td class="fr">标题：<label>*</label></td>
                        <td colspan="3">
                            <input type="text" id="Title" name="Title" style="width:650px;" />
                        </td>
                    </tr>

                    <tr>
                        <td class="fr">消息类型：<label>*</label></td>
                        <td colspan="3">
                            <select class="easyui-combobox" id="Type" name="Type">
                                <option value="1">通知</option>
                                <option value="2">促销活动</option>
                                <option value="3">帮助</option>
                            </select>
                        </td>                        
                    </tr>
                                   
                    <tr>
                        <td class="fr">消息内容：<label>*</label></td>
                        <td colspan="3">
                            <textarea rows="3" style="width:400px;" id="Information_content" name="Information_content" class="easyui-validatebox" @*data-options="required:true,validType:'length[1,1000000]'" invalidMessage="最大长度不能超过1000000""*@></textarea>
                            <input type="hidden" name="Contents" id="Contents" />
                        </td>
                    </tr>

                    <tr>
                        <td colspan="5" align="center" style="padding-top: 10px;">
                            <a href="javascript:void(0)" id="ok" class="easyui-linkbutton" iconcls="icon-ok" style="width: 60px; height: 20px" onclick="submitForm()">保存</a>
                        </td>
                    </tr>
                </table>
                <div id="fileName"></div>
            }
            <div id="dlg_progress" class="easyui-dialog" data-options="modal:true,iconCls:'icon-edit',closed:true" style="width: 600px; padding: 10px 50px 50px 10px;">
                <div id="progressNumber" class="easyui-progressbar" style="width: 400px;">
                </div>
            </div>
        </form>
    </div>
</body>
</html>